package matlap.client.view.distributor;

import matlap.client.services.order.OrderService;
import matlap.client.services.order.OrderServiceAsync;
import matlap.shared.Order;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class NewOrderComposite extends Composite {
//	private HorizontalPanel vp;
	private Label lbName;
	private Button btnSave;
	private TextBox textBox;
	OrderServiceAsync order = GWT.create(OrderService.class);
	private VerticalPanel verticalPanel;
	private HorizontalPanel horizontalPanel;

	public NewOrderComposite(final String un) {
//		vp = new HorizontalPanel();
//		initWidget(vp);
		verticalPanel = new VerticalPanel();
		initWidget(verticalPanel);
		verticalPanel.setSize("544px", "94px");
		DecoratorPanel decoratorPanel = new DecoratorPanel();
		verticalPanel.add(decoratorPanel);
		Label lblNewLabel_2 = new Label("\u00DAj rendel\u00E9s:");
		lblNewLabel_2.setStyleName("BigBold");
		decoratorPanel.setWidget(lblNewLabel_2);

		horizontalPanel = new HorizontalPanel();
		verticalPanel.add(horizontalPanel);

		// Label lblNewLabel_3 = new Label("A jelenlegi rendel\u00E9sek:");
		// lblNewLabel_3.setStyleName("BigBold");
		// vp.add(lblNewLabel_3);

		lbName = new Label("Darab:");
		horizontalPanel.add(lbName);

		textBox = new TextBox();
		horizontalPanel.add(textBox);

//		verticalPanel.add(horizontalPanel);
		
		btnSave = new Button("New button");
		horizontalPanel.add(btnSave);
		btnSave.setText("Ment");
		btnSave.addClickHandler(new ClickHandler() {
			// vp.add(integerBox);

			public void onClick(ClickEvent event) {
				// Date date = Calendar.getInstance().getTime();
				// SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");

				// Date dateNow = new Date ();

				// SimpleDateFormat dateformatYYYYMMDD = new
				// SimpleDateFormat("yyyyMMdd");

				// StringBuilder nowYYYYMMDD = new StringBuilder(
				// dateformatYYYYMMDD.format( dateNow ) );

				Order o = new Order();
				o.setUserName(un);

				o.setDate("2012.05.25");
				o.setNr(Integer.parseInt(textBox.getValue()));
				o.setWho("");
				order.insertOrder(o, new AsyncCallback<Void>() {

					public void onFailure(Throwable caught) {
						Window.alert("Hiba");
					}

					public void onSuccess(Void result) {
						Window.alert("Elmentve");
						textBox.setText("");
					}

				});
			}

		});
	}
}
